import java.util.Scanner;

class TreeNode {
      char val;
      TreeNode left;
     TreeNode right;
     TreeNode() {}
      TreeNode(char val) { this.val = val; }
     TreeNode(char val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
         this.right = right;
     }
  }
 public class Main {
     public static int index = 0;//前序遍历到哪个节点

     public static TreeNode buildTree(char[] preorder, char[] inorder) {
         return creatree(preorder, inorder, 0, inorder.length - 1);


     }

     public static int findindex(char[] inorder, int inbegin, int inend, int val) {
         for (int i = inbegin; i <= inend; i++) {
             if (inorder[i] == val) {
                 return i;
             }
         }
         return -1;
     }

     public static TreeNode creatree(char[] preorder, char[] inorder, int left, int right) {
         if (left > right) {
             return null;
         }


         TreeNode cur = new TreeNode(preorder[index]);
         int rootindex = findindex(inorder, left, right, preorder[index]);//查找前序遍历中的节点在中序遍历中的位置
         if (rootindex == -1) {
             return null;
         }
         index++;
         cur.left = creatree(preorder, inorder, left, rootindex - 1);
         cur.right = creatree(preorder, inorder, rootindex + 1, right);
         return cur;


     }
     public  static  void print(TreeNode root){
         if(root==null){
             return;
         }
         print(root.left);
         print(root.right);
         System.out.print(root.val);

     }

     public static void main(String[] args) {
         Scanner sc = new Scanner(System.in);
         while (sc.hasNextLine()) {
             String s1 = sc.nextLine();
             String s2 = sc.nextLine();
             char[] s11 = new char[s1.length()];
             char[] s22 = new char[s2.length()];
             for (int i = 0; i < s1.length(); i++) {
                 s11[i] = s1.charAt(i);

             }
             for (int i = 0; i < s2.length(); i++) {
                 s22[i] = s1.charAt(i);

             }
             print(buildTree(s11, s22));


         }

     }
 }